<script setup lang="ts">
import { ref, onMounted } from 'vue';
import HomePanel from './homePanel.vue';
import { useHomeStore } from '@/stores/modules/homeStore.ts';
// import { useIntersectionObserver } from '@vueuse/core';
import { useObserver } from '@/hooks';

// 获取 Pinia 中的 home 模块，分类数据为 home.categoryList
const homeStore = useHomeStore();
const { target } = useObserver(homeStore.getHotGoodsList);
// onMounted(() => {
//   // 获取最新商品列表
//   homeStore.getHotGoodsList();
// });

// 通过 ref 获得组件实例
// const target = ref(null);
// const { stop } = useIntersectionObserver(
//   // target 被检测的目标元素
//   target,
//   // isIntersecting 是否进入可视区域
//   ([{ isIntersecting }]) => {
//     // 在此处可根据isIntersecting来判断，然后做业务
//     console.log('是否进入可视区域', isIntersecting);
//     if (isIntersecting) {
//       homeStore.getHotGoodsList();
//       stop();
//     }
//   },
// );
</script>

<template>
  <div class="home-hot" ref="target">
    <HomePanel ref="target" title="人气推荐" sub-title="人气爆款 不容错过">
      <ul class="goods-list">
        <li v-for="item in homeStore.hotGoodsList" :key="item.id">
          <RouterLink :to="`/detail/${item.id}`">
            <img :src="item.picture" alt="" />
            <p class="name">{{ item.title }}</p>
            <p class="desc">{{ item.alt }}</p>
          </RouterLink>
        </li>
      </ul>
    </HomePanel>
  </div>
</template>

<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 426px;
  li {
    width: 306px;
    height: 406px;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}
</style>
